
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link href="../css/main.css" type="text/css" rel="stylesheet" />
		<link href="../css/dialog.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="../datePicker/WdatePicker.js"></script>
		<title></title>
		<style type="text/css">
		textarea{/* width: 340px; */width: 333px;height: 100px;border: #a6d9da solid 1px;padding: 5px;}
			.textarea1{border:none;resize : none;overflow-y:visible }
		</style>
	</head>
	<body>
		<div class="main_frame">
			<div class="position_div">
				<img src="../images/position_icon.png" />
				<i>系统管理</i><i>&gt;&gt;</i><i>字典管理</i>
			</div>
			<div class="right_div">
				<div class="search_div">
				
					<div class="label_div">
						<label class="text_label">字典名称：</label>
					    <div class="drop_frame">
							<i class="text_i" data-status="0" >请选择</i>
							<input type="hidden" id="qry_itemId" value="0">
							<span class="span_arrow"></span>
							<ul class="choose_ul ">
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="0">全部</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="1">项目类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="2">设备类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="3">故障类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="4">保养类型</a>
								</li>
							</ul>
						</div>
					</div>
					<div class="label_div">
						<label class="text_label">名称：</label>
						<input type="text" class="input_search" placeholder="支持模糊查询" id="qry_brand" />
					</div>
					
					
					<div class="done_div">
						<button class="btn_common1 title_div2"  onclick="qryItemListBtn()">
							<i></i>搜索
						</button>
						<button style="margin-left:10px !important" class="btn_common2 newadd"   onclick="toAddForm()">
							<i></i>新增
						</button>
					</div>
                    <div class="cl">&nbsp;</div>
				</div>
				<table class="table_list">
					<tr>
						<th width="6%">序号</th>
						<th width="10%">字典名称</th>
						<th width="10%">关键字</th>
						<th width="10%">代码</th>
						<th width="10%">名称</th>
						<th width="12%">附件</th>
						<th width="15%">备注</th>
						<th class="last_td">操作</th>
					</tr>
					<tbody id="listbox1">
					</tbody>
				</table>
				<div class="turn_page" style="display:none">
				   <div class="main_page" id="pageCon">
					   <a href="javascript:void(0)" class="first_a" id="firstPage"></a>
					   <a href="javascript:void(0)" class="up_a" id="prev"></a>    	
					   <a href="javascript:void(0)" class="next_a" id="next"></a>
					   <a href="javascript:void(0)" class="last_a" id="lastPage"></a>
					   <input id="page_num_input" style="width:40px;" type="text" onblur="checkValue(this);" onkeyup="value=value.replace(/\D/g,'')"/>
					   <button type="button" class="num_input" id="go_num_input">跳转</button>
					   <b class="page_text">当前<i><em id="nowpage"></em>/<em id="totalpage"></em></i>页，总数<i id="totalNum"></i>条</b>    	
				   </div>
				</div>
				
				
				
				
				<div class="opacity_div" style="display: none;"></div>
				<div class="bookDetail" style="display: none;top:150px;">
					<div class="prop_top">
						<i>新增字典</i>
						<a href="javascript:void(0)" class="close_icon"><img src="../images/close_icon.png"></a>
					</div>
					<div class="bookdetail_box">
					<form action="" id="form">
						<div class="blank_div"></div>
						<input type="hidden" class="input_search width_input" name="id" value="0"/>
						<div class="blank_div"></div>
						<label class="text_label label_width">名称：</label>
					    <input type="text" class="input_search width_input notNull" name="name" />
					    &nbsp;&nbsp;<span style="color: red">* </span>
					    
					    <div class="blank_div"></div>
					    
						<label class="text_label label_width">字典名称：</label>
						<div class="drop_frame">
							<i class="text_i" data-status="0"  >请选择</i>
							<span class="span_arrow"></span>
							<input type="hidden" name="type" onchange="chan()">
							<ul class="choose_ul items addchoos">
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="1">项目类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="2">设备类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="3">故障类型</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="4">保养类型</a>
								</li>
							</ul>
						</div>
						<div class="dop_2" style="display:none">
							<div style="float:left; margin:5px;"></div>
							<div class="drop_frame" >
								<i class="text_i addchoos_2_2" data-status="0"  >请选择</i>
								<span class="span_arrow"></span>
								<input type="hidden" name="parentId" value="0">
								<input type="hidden" name="ertypeId" value="0">
								<ul class="choose_ul addchoos_2">
								</ul>
							</div>
					    <div class="blank_div"></div>
					    <label class="text_label label_width">类型：</label>
					    <style>
					    	.ertype{
					    		margin-left: 10px;
					    		    margin-top: 8px;
					    	}
					    </style>
					    <div>
					    	<input type="hidden" value="" id="ertype">
						    <input type="radio" checked="checked"   name="ertype" class="ertype"  value="2" /> BB
						    <input type="radio" name="ertype" class="ertype" value="3" /> CC
						    <input type="radio" name="ertype" class="ertype" value="4" /> DD
					    </div>
					    
						</div>
					    
					    <div class="blank_div"></div>
					    <label class="text_label label_width">关键字：</label>
					    <input type="text" class="input_search width_input notNull" name="keyword" />
					    &nbsp;&nbsp;<span style="color: red">* </span>
					    
					    <div class="blank_div"></div>
					    <label class="text_label label_width">代码：</label>
					       <input type="text" class="input_search width_input notNull" name="code" />
					    &nbsp;&nbsp;<span style="color: red">* </span>
					   
						<div class="blank_div"></div>
					    <label class="text_label label_width">备注：</label>
					    <textarea class="textarea notNull" name="remark" data-maxLen="100" ></textarea>

					    &nbsp;&nbsp;<span style="color: red">* </span>
						
						
					</form>
					<div class="blank_div"></div>
					<div class="blank_div"></div>
					<div class="bottom_donebtn width_div">
						<button class="btn_common2"  onclick="itemFormSubmit()">提交</button>
						<button class="btn_common1" onclick="edit_cancel()">取消</button>	
					</div>
					
					</div>
					<div class="blank_div"></div>
					<div class="blank_div"></div>
				</div>
				
				
			
			
				
				
				
			</div>
		</div>
		<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/dialog.js"></script>
		<script type="text/javascript" src="../js/jquery-data.js"></script>
		<script type="text/javascript">
		var type_array=["","项目类型","设备类型","故障类型","保养类型"]
			var yema=1;
			var pagelen=10;
			var totalPage=0;   
			function qryList(){		
				qryItemList();
			}
			
			$(document).ready(function(){
				
				qryList();
			});
			function qryList(){
				qryItemList();
			}
			function qryItemListBtn(){
				 yema=1;
				qryItemList();
			}
			function qryItemList(){
				$.ajax({
					url: 'qryDictionaryList', 
					type: 'POST',
					data:{type:$("#qry_itemId").val(),
						name:$("#qry_brand").val(),
						yema:yema,length:pagelen},
					async: false,
					dataType: 'json', 
					timeout: 10000, 
					error: function(){LQWarn('请求失败,请稍后重试');}, 
					success: function(result){
						
						if(result.resultCode==1000){
							var items=result.returnObject.pageList;
							if (items && items.length > 0) {
								var rlist="";
								var item ;
								
								$.each(items,function(i){
									item = items[i];
									rlist+='<tr data-status ="'+ item.id+'"><td>'
										+ (i+1+length*(result.returnObject.curPage-1))
										+ '</td><td>' 
										+ type_array[item.type]
										+ '</td><td>' 
										+ item.keyword
										+ '</td><td>' 
										+ item.code
										+ '</td><td>' 
										+ item.name
										+ '</td><td>' 
										+ replaceNull(item.attachment)
										+'</td><td>'
										+ item.remark
										+'</td><td class="last_td">'
										+ '<a class="mod" title="修改" href="javascript:void(0);" onclick="toEditForm(this)">修改</a>'
										+ '<a class="del" title="删除" href="javascript:void(0);" onclick="delItem(this)">删除</a>'
										
										+ '</td></tr>';
								});
								$("#listbox1").html(rlist);
								totalPage=result.returnObject.totalPage;
								$("#nowpage").html(result.returnObject.curPage);
								$("#totalpage").html(totalPage);
								$("#totalNum").html(result.returnObject.totalNum);
								$(".turn_page").show();
							}else{
								$("#listbox1").html("");
								$(".turn_page").hide();
							}
						}
						else if(result.resultCode==1004){
							LQWarn(result.returnObject);
							window.top.location.href ="../login.jsp";
						}else{
							LQWarn(result.returnObject);
						}
					}
				});
			}
			var dy = 0;
			var code_a = 0;
			$(".addchoos .choose_a").click(function(){
				 var tt =  $(this).text();
				 var dtype =  $(this).attr("data-status");
				 if(dtype==2){
				    console.log("设备类型");
				    $(".dop_2").show();
				 }else{
				    $(".dop_2").hide();
				   /*  $(".addchoos_2_2").html("请选择");
                    $("input[name='parentId']").val(0);
                    $("input[name='ertypeId']").val(0); */
				 }
				 console.log(tt+"="+dtype);
				 dy=dtype;
				 qryDicTypes();
			})
			
			$(".ertype").click(function() {
				$("input[name='ertypeId']").val($(this).val());
				console.log($(this).val());
			})
			

			function qryDicC(code){
				var e =  $("input[name='ertypeId']").val();
				if (e!=0) {
					$("input[name='ertype']").eq(e).click();
				}else {
					$("input[name='ertype']").eq(0).click();
				}
				$("input[name='parentId']").val(code);
				
			}
			//查询下拉框字典
            function qryDicTypes(){
                $.ajax({
                    url: 'qryDictionaryList', 
                    type: 'POST',
                    data:{type:dy,
                    parentId:code_a,
                        yema:1,length:1000},
                    async: false,
                    dataType: 'json', 
                    timeout: 10000, 
                    error: function(){LQWarn('请求失败,请稍后重试');}, 
                    success: function(result){
                        console.log(result);
                        if(result.resultCode==1000){
                            var items=result.returnObject.pageList;
                            if (items && items.length > 0) {
                                var rlist="";
                                var item ;
                                //rlist+='<li><a href="javascript:void(0)"  class="choose_a" onclick="qryDicC(0)" data-status="">请选择</a> </li>';
                                $.each(items,function(i){
                                    item = items[i];
                                    rlist+='<li><a href="javascript:void(0)" onclick="qryDicC('+item.id+')" class="choose_a" data-status="'+item.id+'">'+item.name+'</a> </li>';
                                });
                                $(".addchoos_2").html(rlist);
                            }else{
                                $(".addchoos_2").html("");
                            }
                        }
                        else if(result.resultCode==1004){
                            LQWarn(result.returnObject);
                            window.top.location.href ="../login.jsp";
                        }else{
                            LQWarn(result.returnObject);
                        }
                    }
                });
            }
			
			
			
			var url_ = "addDictionary.do";
			
			function toAddForm(){
				$(".opacity_div,.bookDetail").show();	
				url_ = "addDictionary.do";
				dy=0;
				code_a=0;
				$("input[name='parentId']").val(0);
				$("input[name='ertypeId']").val(0);
				$(".dop_2").hide();
				$("#form").clearForm();
			}

			
			function itemFormSubmit(){
				
				var typeval = $("input[name='type']").val();
				if (typeval!=2) {
					$("input[name='parentId']").val(0)
					
				}else {
				var c = $("input[name='parentId']").val();
					if (c==0) {
						$("input[name='ertypeId']").val(0)
					}
				}
			//	console.log($("#form").serialize());
					if($("#form").checkhaveNull()){
					return;
				}
				operateObject(url_,$("#form").serialize(),function(){edit_cancel();});
				//return;
				
			}
			
			
			function toEditForm(obj){
				var id = $(obj).parents("tr").attr("data-status");
				toAddForm();
				
				
				url_ = "editDictionary.do";
				getObjectWithFillData("qryDictionaryById.do",{"id":id},$("#form"),'editInof');
				
			}
			
			
			function editInof(obj){
			     console.log(obj);
			     var ite = obj.returnObject;
			     
			     var tt = obj.returnObject.ertypeId;
			     
			     $("input[name='parentId']").val(obj.returnObject.parentId);
			     $("input[name='ertypeId']").val(obj.returnObject.ertypeId);
			     if (tt) {
				     var ttt= (Number(tt)-2);
				    $("input[name='ertype']").eq(ttt).click();
				}
				
				
				/* var c =  $("input[name='parentId']").val();
				if (c==0) {
				    $("input[name='ertype']").removeClass('default');
				} */
				
				
			    /*   $("input[name='ertype']").eq(2).addClass('default');
			      var vv =  $("input[name='ertype']").eq(2).val();
			      console.log(vv); */
                 /* if(ite.cname){
                     $(".addchoos_2_2").text(ite.cname);
                     $(".addchoos_2_2").attr("data-status",ite.cid);
                      if(ite.bname){
		                    $(".addchoos_3_3").text(ite.bname);
		                    $(".addchoos_3_3").attr("data-status",ite.bid);
		              }
                 }else{
                     $(".addchoos_2_2").text(ite.bname);
                     $(".addchoos_2_2").attr("data-status",ite.bid);
                 } */
                 
                
                 
                 
			}
			
			function delItem(obj){
				
				var id = $(obj).parents("tr").attr("data-status");
				delObject('delDictionary.do',{"id":id});
				
				
			}
			
			function edit_cancel(){
				$(".opacity_div,.bookDetail").hide();
			}
			
			
				
		</script>
	</body>
</html>
